<template>
  <div class="payment pay">
    <van-nav-bar
      title="支付"
      left-text="返回"
      left-arrow
      @click-left="$router.go(-1)"
    />

    <div class="ctxPay">
      <div data-v-74bbaf8a="">
        <img data-v-74bbaf8a="" :src="payInfo.qrcode" alt="" />
      </div>
      <div class="pricePay">￥{{ payInfo.allFee | fMoney }}</div>
    </div>
    <div class="context">
      <div class="collectPay">
        <div class="leftPay">收款方</div>
        <div class="rightPay">天堂电子商务有限公司</div>
      </div>
      <div class="collectPay">
        <div class="leftPay">剩余支付时间</div>
        <div class="rightPay">
          <van-count-down  @finish="finish" :time="time" format="mm 分 ss 秒" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import $http from "@/utils/request.js";
export default {
  data() {
    return {
        timer: null,
      payInfo: {
            // 总金额
        allFee: "",
        // 创建时间
        createTime: "",
        // 订单编号
        orderId: "",
        // 支付二维码
        qrcode: "",
      },
    };
  },
  computed:{
      time(){
        let allTime = 15 * 60 * 1000;
        let passTime = Date.now() - this.payInfo.createTime;
        let time = allTime -passTime;
        return time
      }
  },
  created() {
    this.payInfo = this.$route.query;
    this.getPayResult();
  },
  destroyed(){
      clearInterval(this.timer)
  },
  methods: {
      getPayResult(){
        this.timer = setInterval(()=>{
            let params = {
                orderId:this.payInfo.orderId,
            };
            $http.get('order/detail',{params}).then(res =>{
                if(res.result.orderStatus === '01') {
                    clearInterval(timer);
                    this.$router.push('/')
                }
            })
        })
      },
       finish(){
           this.$router.push('/')
       }
  },
};
</script>

<style lang="less" scoped>
.pay {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  .van-nav-bar__title {
    font-size: 17px;
  }
  .van-icon,
  .van-icon::before {
    color: #c03131;
    //   font-size: 23px;
    font-weight: 100;
  }
  .ctxPay {
    width: 100vw;
    text-align: center;
    img {
      width: 80%;
    }
    .titlePay {
      margin-top: 20px;
      font-size: 15px;
      color: #2c3e50;
      height: 22px;
      line-height: 22px;
    }
    .pricePay {
      margin-top: 20px;
      color: #2d3e4f;
      font-size: 30px;
      font-weight: 700;
      height: 45px;
      line-height: 45px;
    }
  }
  .context {
    width: 100vw;
    border-top: 1px solid #eae8e8;

    margin-top: 10px;
    color: #2c3e50;
    .collectPay {
      height: 49px;
      line-height: 49px;
      font-size: 15px;
      margin: 0 15px;
      display: flex;
      justify-content: space-between;
    }
  }
  .btnPay {
    width: 97.5%;
    margin: 0 auto;
    .van-button {
      border-radius: 10px;
      margin-top: 28px;
      background: #04be01;
    }
  }
  .van-button {
    height: 45px;
    line-height: 45px;
    font-size: 15px;
  }
  .pay .van-icon-arrow-left {
    font-size: 16px !important;
  }
}
</style>
